<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
                xmlns:lxslt="http://xml.apache.org/xslt"
                xmlns:redirect="http://xml.apache.org/xalan/redirect"
                extension-element-prefixes="redirect">

    <!--
    Creates an all-classes.html file that contains a link to all files.
    -->
    <xsl:template match="checkstyle" mode="all.files">
        <html>
            <head>
                <link rel="stylesheet" type="text/css" href="stylesheet.css"/>
            </head>
            <body>
                <h2>Files</h2>
                <p>
                    <ul>
                        <xsl:apply-templates select="checktype" mode="all.checktype.files">
                            <xsl:sort select="@type"/>
                        </xsl:apply-templates>
                    </ul>
                </p>
            </body>
        </html>
    </xsl:template>


    <xsl:template match="checktype" mode="all.checktype.files">
        <xsl:variable name="fileCount" select="count(.//file)"/>
        <xsl:variable name="errorCount" select="count(.//error)"/>
        <li class="checktype">
            <a target="mainFrame">
                <xsl:attribute name="href">
                    <xsl:text>files/</xsl:text>
                    <xsl:value-of select="@type"/>
                    <xsl:text>.html</xsl:text>
                </xsl:attribute>
                <xsl:value-of select="@type"/>
            </a>
            (files:<xsl:value-of select="$fileCount"/>, errors:<xsl:value-of select="$errorCount"/>)
            <ul>
                <xsl:apply-templates select="folder" mode="list.folder">
                    <xsl:with-param name="parent-folder" select="''"/>
                </xsl:apply-templates>
            </ul>
        </li>
    </xsl:template>

    <xsl:template match="folder" mode="list.folder">
        <xsl:param name="parent-folder"/>
        <xsl:variable name="new-name">
            <xsl:call-template name="from-dos">
                <xsl:with-param name="path" select="@name"/>
            </xsl:call-template>
        </xsl:variable>
        <xsl:variable name="fileCount" select="count(.//file)"/>
        <xsl:variable name="errorCount" select="count(.//error)"/>


        <li class="folder">
            <a target="mainFrame">
                <xsl:attribute name="href">
                    <xsl:text>files/</xsl:text>
                    <xsl:value-of select="concat($parent-folder,$new-name)"/>
                    <xsl:text>summary.html</xsl:text>
                </xsl:attribute>
                <xsl:value-of select="@name"/>
            </a>
            (files:<xsl:value-of select="$fileCount"/>, errors:<xsl:value-of select="$errorCount"/>)
            <ul>
                <xsl:apply-templates select="file" mode="list.file">
                    <xsl:with-param name="parent-folder" select="concat($parent-folder,$new-name)"/>
                </xsl:apply-templates>
                <xsl:apply-templates select="folder" mode="list.folder">
                    <xsl:with-param name="parent-folder" select="concat($parent-folder,$new-name)"/>
                </xsl:apply-templates>
            </ul>
        </li>
    </xsl:template>


    <xsl:template match="file" mode="list.file">
        <xsl:param name="parent-folder"/>
        <xsl:variable name="errorCount" select="count(./error)"/>

        <li class="file">
            <a target="mainFrame">
                <xsl:attribute name="href">
                    <xsl:text>files/</xsl:text>
                    <xsl:value-of select="concat($parent-folder,@path)"/>
                    <xsl:text>.html</xsl:text>
                </xsl:attribute>
                <xsl:value-of select="@path"/>
            </a>
            (errors:<xsl:value-of select="$errorCount"/>)
        </li>
    </xsl:template>

</xsl:stylesheet>